package cn.com.bob.messageboard.controller;

import cn.com.bob.messageboard.domain.JsonResult;
import cn.com.bob.messageboard.service.impl.EmailServiceImpl;
import cn.com.bob.messageboard.utils.VerificationCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

import static cn.com.bob.messageboard.controller.BaseController.OK;

/**
 * @Author Bob
 * @Version：1.0
 * 发送邮箱验证码
 */
@RestController
public class VerificationCodeController {
    @Autowired
    private EmailServiceImpl emailService;

    public static Map<String,String> emailMap = new HashMap<>();

    @PostMapping("/sendVerificationCode")
    public JsonResult<String> sendVerificationCode(String email) {
        // 生成验证码
        String verificationCode = VerificationCodeUtil.generateVerificationCode(6);
        System.out.println(email);

        // 发送验证码邮件
        emailService.sendVerificationCode(email, verificationCode);
        emailMap.put("emailCode",verificationCode);
        return new JsonResult<>(OK,"验证码已发送至您的邮箱，请注意查收！");
    }
}
